/* clock em Hz */
#define F_CPU 8000000UL

#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>

#include "att2313/serial.h"

void main_init(void) {

  serial_init((F_CPU/SERIAL_BAUD/16)-1);
  /* set PC5 to output */
  DDRB |= 1 << PB4;
  PORTB &= ~(1 << PB4);
  _delay_ms(250);

}

int main(void) {

  char msg[10];

  main_init();
  /* Enable Interrupts */
  sei();

  while(1) {
    if (serial_rx==1) {
      PORTB |= 1 << PB4;
      serial_read_buffer(msg);
      serial_transmit(msg);
      _delay_ms(100);
      PORTB &= ~(1 << PB4);
    }
/*     PORTB |= 1 << PB4; */
/*     _delay_ms(1000); */
/*     PORTB &= ~(1 << PB4); */
/*     _delay_ms(1000); */
  }

  return 0;

}
